import Vue from 'vue'
import VueRouter from 'vue-router'
import store from "../store";

Vue.use(VueRouter)

const routes = [
    {
      path: '/',
      name: 'Manage',
      component: () => import('../views/Manage'),
      redirect: "/front/home",
      children: [
        {path: 'home', name: '首页', component: () => import('../views/Home')},
        {path: 'user', name: '用户管理', component: () => import('../views/User')},
        {path: 'person', name: '个人信息', component: () => import('../views/Person')},
        {path: 'password', name: '修改密码', component: () => import('../views/Password')},
        {path: 'File', name: '文件管理', component: () => import('../views/File')},
        {path: 'area', name: '地区管理', component: () => import('../views/Area')},
        {path: 'hospital', name: '医院管理', component: () => import('../views/Hospital')},
        {path: 'department', name: '科室管理', component: () => import('../views/Department')},
        {path: 'disease', name: '疾病管理', component: () => import('../views/Disease')},
        {path: 'information', name: '文章管理', component: () => import('../views/Information')},
        {path: 'appraise', name: '评论管理', component: () => import('../views/Appraise')},
        {path: 'stage', name: '问诊时间管理', component: () => import('../views/Stage')},
        {path: 'order', name: '订单管理', component: () => import('../views/Order')},
        {path: 'physician', name: '医师管理', component: () => import('../views/Physician')},
        {path: 'role', name: '角色管理', component: () => import('../views/Role')},
        {path: 'menu', name: '菜单管理', component: () => import('../views/Menu')},
        {path: 'question', name: '问题管理', component: () => import('../views/Question')},
        {path: 'reply', name: '回复管理', component: () => import('../views/Reply')},
        {path: 'province', name: '省份管理', component: () => import('../views/Province')},
        {path: 'hosDep', name: '医院科室管理', component: () => import('../views/HosDep')},
      ]
    },
    {
      path: '/about',
      name: 'About',
      component: () => import('../views/About')
    },
    {
      path: '/login',
      name: 'Login',
      component: () => import('../views/Login')
    },
    {
      path: '/adminLogin',
      name: 'AdminLogin',
      component: () => import('../views/AdminLogin')
    },
    {
      path: '/phyLogin',
      name: 'PhyLogin',
      component: () => import('../views/PhyLogin')
    },
    {
      path: '/register',
      name: 'Register',
      component: () => import('../views/Register')
    },
    {
      path: '/phyRegister',
      name: 'PhyRegister',
      component: () => import('../views/PhyRegister')
    },
  {
    path: '*',
    name: 'notFound',
    component: () => import('../views/404')
  },

    {
      path: '/front',
      name: 'Front',
      component: () => import('../views/front/Front'),
      redirect: "/login",
      children: [
        {path: 'home', name: '首页', component: () => import('../views/front/Home')},
        {path: 'phyInfo', name: 'PhyInfo', component: () => import('../views/front/PhyInfo')},
        {path: 'userPerson', name: 'UserPerson', component: () => import('../views/front/UserPerson')},
        {path: 'userPassword', name: 'UserPassword', component: () => import('../views/front/UserPassword')},
        {path: 'order', name: 'UserOrder', component: () => import('../views/front/Order')},
        {path: 'comment', name: 'Comment', component: () => import('../views/front/Comment')},
        {path: 'article', name: 'Article', component: () => import('../views/front/Article')},
        {path: 'fastOrder', name: 'FastOrder', component: () => import('../views/front/FastOrder')},
        {path: 'physician', name: 'SelectPhysician', component: () => import('../views/front/Physician')},
        {path: 'duoWen', name: 'DuoWen', component: () => import('../views/front/DuoWen')},
        {path: 'question', name: 'QuestionDetail', component: () => import('../views/front/Question')},
        {path: 'personQue', name: 'PersonQue', component: () => import('../views/front/PersonQue')},
        {path: 'im', name: 'Im', component: () => import('../views/Im')},
        {path: 'hosInfo', name: 'HosInfo', component: () => import('../views/front/HosInfo')},
        {path: 'hosPhy', name: 'LookHosPhy', component: () => import('../views/front/HosPhy')},
        {path: 'disInfo', name: 'DisInfo', component: () => import('../views/front/DisInfo')},
        {path: 'articleList', name: 'ArticleList', component: () => import('../views/front/ArticleList')},
        {path: 'hospital', name: 'AllHospital', component: () => import('../views/front/HospitalList')},
        {path: 'physicianList', name: 'PhysicianList', component: () => import('../views/front/PhysicianList')},
        {path: 'depInfo', name: 'DepInfo', component: () => import('../views/front/DepInfo')},
      ]
    },
    {
      path: '/editor',
      name: 'Editor',
      component: () => import('../views/doctor/Editor')
    },
    {
      path: '/doctor',
      name: 'Doctor',
      component: () => import('../views/Doctor'),
      children: [
        {path: 'home', name: 'DocHome', component: () => import('../views/doctor/Home')},
        {path: 'phyPerson', name: 'PhyPerson', component: () => import('../views/doctor/PhyPerson')},
        {path: 'phyPassword', name: 'PhyPassword', component: () => import('../views/doctor/PhyPassword')},
        {path: 'stage', name: 'DocStage', component: () => import('../views/doctor/Stage')},
        {path: 'application', name: 'Application', component: () => import('../views/doctor/Application')},
        {path: 'reply', name: 'DocReply', component: () => import('../views/doctor/Reply')},
        {path: 'question', name: 'answerQuestion', component: () => import('../views/doctor/Question')},
        {path: 'im', name: 'DocIm', component: () => import('../views/doctor/Im')},
      ]
    },
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})


//路由守卫
router.beforeEach((to, from, next) => {
    localStorage.setItem("currentPathName", to.name) //设置当前的路由名称 为了在Header组件中去使用
    store.commit("setPath") //触发store的数据更新
    next() //放行路由
  })

router.afterEach((to,from,next) => {
  window.scrollTo(0,0);
})

export default router


